//
//  ZQSettingViewController.m
//  BuDeJie
//
//  Created by 仲琦 on 16/4/4.
//  Copyright © 2016年 仲琦. All rights reserved.
//

#import "ZQSettingViewController.h"
#import <SDImageCache.h>
#import "ZQFileManager.h"
static NSString * const ID = @"cell";

//获取cache这个文件夹路径

#define cachePath  NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0]
@implementation ZQSettingViewController

- (void)viewDidLoad
{
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:ID];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID forIndexPath:indexPath ];
    
    NSInteger size = [[SDImageCache sharedImageCache] getSize];
    
    NSLog(@"%ld", size);
    
    cell.textLabel.text = [self getFileSize];
  
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    //工具类 删除缓存方法
    [ZQFileManager removeDirectoryPath:cachePath];
    //刷新tableView
    [self.tableView reloadData];
}



- (NSString *)getFileSize
{
    
    //获取cache这个文件夹路径
    
    //获取 总大小
    NSInteger totalSize = [ZQFileManager getDictionarySize:cachePath];
    
    
    NSString *str = @"清除缓存";
    
    if (totalSize > 10000 *10000) {
        CGFloat totalSizeF =totalSize / 1000.0 /1000.0 ;
        str = [NSString stringWithFormat:@"%@ (%.1fMB)", str, totalSizeF];
    }else if (totalSize > 10000) {
        CGFloat totalSizeF =totalSize / 1000.0;
        str = [NSString stringWithFormat:@"%@ (%.1fKB)", str, totalSizeF];
    }else { // B
        str = [NSString stringWithFormat:@"%@(%ldB)",str,totalSize];
    }
    NSLog(@"%@", str);
    return str;

}




@end
